import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/items/labEntrustItems/list',
  save = '/items/labEntrustItems/add',
  edit = '/items/labEntrustItems/edit',
  deleteOne = '/items/labEntrustItems/delete',
  deleteBatch = '/items/labEntrustItems/deleteBatch',
  importExcel = '/items/labEntrustItems/importExcel',
  exportXls = '/items/labEntrustItems/exportXls',

  basicMList = '/items/labItemsBasic/list',
  basicList = '/items/labItemsTemp2Basic/list',
  basicSave = '/items/labItemsTemp2Basic/add',
  basicEdit = '/items/labItemsTemp2Basic/edit',
  basicDelOne = '/items/labItemsTemp2Basic/delete',
  basicQueryById = '/items/labItemsTemp2Basic/queryById',
  addBasic = '/items/labItemsTemp2Basic/addBasic',

  normMList = '/items/labItemsNorm/list',
  normList = '/items/labItemsTemp2Norm/list',
  normSave = '/items/labItemsTemp2Norm/add',
  normEdit = '/items/labItemsTemp2Norm/edit',
  normDelOne = '/items/labItemsTemp2Norm/delete',
  normDelBatch = '/items/labItemsTemp2Norm/deleteBatch',
  addNorm = '/items/labItemsTemp2Norm/addNorm',

  targerMList = '/items/labItemsTarget/list',
  targetList = '/items/labItemsTemp2Target/list',
  targetSave = '/items/labItemsTemp2Target/add',
  targetEdit = '/items/labItemsTemp2Target/edit',
  targetdelOne = '/items/labItemsTemp2Target/delete',
  addTarget = '/items/labItemsTemp2Target/addTarget',

  personMList = '/items/labItemsPerson/list',
  perList = '/items/labItemsTemp2Person/list',
  perSave = '/items/labItemsTemp2Person/add',
  perEdit = '/items/labItemsTemp2Person/edit',
  perDelOne = '/items/labItemsTemp2Person/delete',
  perDelBatch = '/items/labItemsTemp2Person/deleteBatch',
  addPerson = '/items/labItemsTemp2Person/addPerson',
  createTemp2 = '/items/labEntrustItems/createTemp2',
  submitResearch = '/items/labTaskAllot/submitResearch'
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};

/**
 * 列表接口
 * @param params
 */
export const normList = (params) => defHttp.get({ url: Api.normList, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const normDelOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.normDelOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const normDelBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.normDelBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 提交临时任务到检测实验处
 * @param params
 * @param handleSuccess
 * @returns
 */
export const submitOneEntss = (params, handleSuccess) => {
  return defHttp.post({ url: Api.submitResearch, params}, { isTransformResponse: false }).then(() => {
    handleSuccess();
  });
};
/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const normSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.normSave : Api.normEdit;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};

/**
 * 列表接口 实验项目检测条件列表查询
 * @param params get
 */
export const normMList = (params?) => defHttp.get({ url: Api.normMList, params });

/**
 * 列表接口 实验项目- 检测条件列表 - 新增或更新
 */
export const addNorm = (params) => {
  return defHttp.post({ url: Api.addNorm, params }, { isTransformResponse: false });
};

/**
 * 列表接口
 * @param params
 */
export const basicList = (params?) => defHttp.get({ url: Api.basicList, params });

/**
 * 根据id查询
 * @param params
 * @returns
 */
export const basicQueryById = (params) => defHttp.get({ url: Api.basicQueryById, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const basicDelOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.basicDelOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const basicSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.basicSave : Api.basicEdit;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};

/**
 * 列表接口 实验项目基础信息列表查询
 * @param params get
 */
export const basicMList = (params?) => defHttp.get({ url: Api.basicMList, params });

/**
 * 列表接口 实验项目- 基础信息列表 - 新增或更新
 */
export const addBasic = (params) => {
  return defHttp.post({ url: Api.addBasic, params }, { isTransformResponse: false });
};

/**
 * 列表接口
 * @param params
 */
export const personList = (params?) => defHttp.get({ url: Api.perList, params });

/**
 * 列表接口
 * @param params
 */
export const targerMList = (params?) => defHttp.get({ url: Api.targerMList, params });

/**
 * 列表接口
 * @param params
 */
export const targetList = (params?) => defHttp.get({ url: Api.targetList, params });

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const targetSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.targetSave : Api.targetEdit;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const targetdelOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.targetdelOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 保存或者更新
 * @param params
 */
export const addTarget = (params) => {
  return defHttp.post({ url: Api.addTarget, params }, { isTransformResponse: false });
};

/**
 * 列表接口
 * @param params
 */
export const perList = (params) => defHttp.get({ url: Api.perList, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const perDelOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.perDelOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const perDelBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.perDelBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const perSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.perEdit : Api.perSave;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};
/**
 * 实验人员列表接口
 * @param params
 */
export const personMList = (params) => defHttp.get({ url: Api.personMList, params });
/**
 * 实验人员添加进模板
 */
export const addPerson = (params) => {
  return defHttp.post({ url: Api.addPerson, params }, { isTransformResponse: false });
};

/**
 * 生成模板
 * @param params
 * @param isUpdate
 */
export const createTemp2 = (params) => {
  let url = Api.createTemp2;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};
